<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <div class="filter-item" style="margin-right:20px;">
        <span class="txt">推荐：</span>
        <el-radio-group v-model="search.status">
          <el-radio :label="-1">全部</el-radio>
          <el-radio :label="0">是</el-radio>
          <el-radio :label="1">否</el-radio>
        </el-radio-group>
      </div>
      <el-input class="filter-item" @keyup.enter.native="handleFilter" style="width: 200px;" placeholder="请输入关键词" v-model="search.keyword"></el-input>
      <el-button class="filter-item" v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>
    <el-table v-loading="!pload" ref="multipleTable" border :data="tableData">
      <el-table-column property="roomNo" label="直播间id" show-overflow-tooltip></el-table-column>
      <el-table-column property="topicName" label="主题名称" show-overflow-tooltip></el-table-column>
      <el-table-column property="userName" label="创建者" show-overflow-tooltip></el-table-column>
      <el-table-column property="notice" label="公告" show-overflow-tooltip></el-table-column>
      <el-table-column property="number" label="参与人数" show-overflow-tooltip></el-table-column>
      <el-table-column label="创建时间" show-overflow-tooltip width="200">
        <template slot-scope="scope">
          <span>{{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" width="100" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-tag type="success" size="mini" v-if="!scope.row.status">推荐</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180" align="center">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">查看</el-button>
          <el-button size="mini" @click="handleTj(scope.$index, scope.row)">{{scope.row.status ? '' : '取消'}}推荐</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-size="limit" :page-sizes="limits" background layout="sizes, prev, pager, next, jumper, total" :total="count">
      </el-pagination>
    </div>
    <edit v-if="edit" :data="selectTable" @close="edit=false"></edit>
  </div>
</template>
<script>
import * as api from '@/utils/api'
import waves from '@/directive/waves' // 水波纹指令
import edit from './edit'
export default {
  directives: {
    waves
  },
  data () {
    return {
      edit: false,
      selectTable: {},
      tableData: [],
      search: {
        keyword: '',
        status: -1
      },
      pload: false,
      currentPage: 1,
      limit: 10,
      limits: [10, 20, 50, 100],
      count: 0
    }
  },
  components: {
    edit
  },
  created () {
    this.getData()
  },
  methods: {
    async handleTj (index, row) {
      let tj = row.status ? '' : '取消'
      tj += '推荐'
      this.$confirm('确认要' + tj + '吗', { type: 'warning' }).then(async () => {
        try {
          this.pload = false
          await api.tjZBtopic({ ids: row.topicId, status: row.status ? 0 : 1 })
          this.$notify({ title: '操作成功', type: 'success', duration: 5000 })
          this.getData()
        } catch (e) {
          this.pload = true
        }
      })
    },
    async getData () {
      const data = { pageNum: this.currentPage, pageSize: this.limit, ...this.search }
      this.pload = false
      const Datas = await api.getZBtopicList(data)
      this.tableData = Datas.list
      this.count = Datas.total
      this.pload = true
    },
    handleEdit(index, row) {
      this.selectTable = JSON.parse(JSON.stringify(row))
      this.edit = true
    },
    handleFilter () {
      this.currentPage = 0
      this.getData()
    },
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
      this.limit = val
      this.getData()
    },
    handleCurrentChange (val) {
      this.currentPage = val
      this.getData()
    }
  }
}
</script>
